<html>
<head>
	<meta charset="UTF-8">
	<meta content="IE=edge" http-equiv="X-UA-Compatible">
	<meta content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no, width=device-width" name="viewport">
	<title>4528：LotteryTree</title>
	<!-- css -->
	<link href="../css/base.min.css" rel="stylesheet">
	<link href="../css/project.min.css" rel="stylesheet">
	
	<!-- favicon -->
	<!-- ... -->
</head>
<body class="page-brand">
	<header class="header header-transparent header-waterfall ui-header">
		<ul class="nav nav-list pull-left">
			<li>
				<a data-toggle="menu" href="#menu">
					<span class="icon icon-lg">menu</span>
				</a>
			</li>
		</ul>
		<a class="header-logo header-affix-hide margin-left-no margin-right-no" data-offset-top="213" data-spy="affix">LotteryTree</a>
		<span class="header-logo header-affix margin-left-no margin-right-no" data-offset-top="213" data-spy="affix">LotteryTree</span>
	</header>
	<nav aria-hidden="true" class="menu" id="menu" tabindex="-1">
		<div class="menu-scroll">
			<div class="menu-content">
				<a class="menu-logo" href="../index.html">BZOJ离线题库</a>
				<ul class="nav">
					<li>
						<a class="waves-attach" data-toggle="collapse" href="#problems">题目</a>
						<ul class="menu-collapse collapse in" id="problems">
							<li>
								<a class="waves-attach" href="../index.html">主页</a>
							</li>
							<li>
								<a class="waves-attach" href="../list.html">题目列表</a>
							</li>
						</ul>
					</li>
					<li>
						<a class="collapsed waves-attach" data-toggle="collapse" href="#about">关于</a>
						<ul class="menu-collapse collapse" id="about">
							<li>
								<a class="waves-attach" href="../about.html">关于此项目</a>
							</li>
						</ul>
					</li>
					
				</ul>
			</div>
		</div>
	</nav>
	<main class="content">
		<div class="content-header ui-content-header">
			<div class="container">
				<h1 class="content-heading">
                LotteryTree                </h1>
                <p>时间限制：20s&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  空间限制：256MB</p>			</div>
		</div>
		<div class="container">
			<section class="content-inner margin-top-no">
				<div class="row">
					<div class="col-lg-13 col-md-13">
						<div class="card margin-bottom-no">
							<div class="card-main">
								<div class="card-inner">
									
                                <h3>题目描述</h3><p><div>你发行了一种彩票，并且有P人买了它。现在你要决定谁中奖。</div>
<div>你已经决定了用一个有根树来选择优胜者。你需要做的事情被列在下面：</div>
<div>&bull;参与者从1到P连续编号。</div>
<div>&bull;首先，你将树画在一个矩形的白板上，并需要满足以下条件：</div>
<div>&ndash;树上的每一个结点对应白板上的一个圆圈。圆圈很小以至于你可以</div>
<div>忽略他们的大小。</div>
<div>&ndash;树上的每条边对应连接两个圈的线段。没有两条边相交。</div>
<div>&ndash;根节点一定画在白板的最上方。</div>
<div>&ndash;对于每个结点，连向它们儿子们的边都要向下走。（换句话说，父亲</div>
<div>必须画在儿子的上方。）</div>
<div>&ndash;所有的叶子需画在白板的底边。</div>
<div>&bull;接下来，你将白板的底边分成P段，每个叶子被恰好一条线段包含。将1</div>
<div>到P这些个不同的数字分配给每个线段，然后将数字标注在线段内的叶子上。</div>
<div>&bull;现在，你要重复下述过程：找到一个空结点X，它的所有儿子都标注了数</div>
<div>字；如果有多个这样的结点，随机选择一个；然后在X的儿子中随机选</div>
<div>择一个，将这个儿子的数字标注在X上；当根节点被标上数字时过程结</div>
<div>束。</div>
<div>你会获得整数P和用于描述你使用的树的数组tree。这棵树有N个结点，</div>
<div>从0到N-1编号。结点0是树根。对于每个其他结点，它父亲的编号小于它的</div>
<div>编号。更正式的说，对于在1和N-1之间的i，tree[i]是结点i父亲的编号。</div>
<div>你想要让抽奖公平，即，保证每个参与者有相同的机率赢取大奖。为此，你可以</div>
<div>在合法的要求下选择怎样画这棵树，以及怎样分配数字到叶子上。回答&ldquo;YES&rdquo;</div>
<div>（不需要引号）如果抽奖可以公平，否则回答&ldquo;NO&rdquo;。</div>
<div></div>
<p></p></p><hr/><h3>输入格式</h3><p><div>多组数据，读入到文件结束。</div>
<div>每组数据第一行读入两个整数N和P&mdash;&mdash;所用树的大小以及参与者人数。</div>
<div>第二行读入N-1个整数，描述数组tree；其中第i个整数为tree[i]。</div>
<div></div>
<p></p></p><hr/><h3>输出格式</h3><p><div>每组数据输出单独一行一个单词&ldquo;YES&rdquo;或&ldquo;NO&rdquo;</div>
<div></div>
<p></p></p><hr/><h3>样例输入</h3><pre>4 3
0 0 0
10 2
0 0 0 1 1 2 2 3 3
10 3
0 0 1 1 2 2 4 4 4
9 3
0 0 1 1 1 3 3 3</pre><hr/><h3>样例输出</h3><pre>YES
YES
NO
NO</pre><hr/><h3>提示</h3><p><p>P&le;N&le;100</p></p><hr/><h3>题目来源</h3><p>没有写明来源</p>
								</div>
							</div>
						</div>
					</div>
				</div>
				
				
			</section>
		</div>
	</main>

	<div class="fbtn-container">
		<div class="fbtn-inner">
			<a class="fbtn fbtn-lg fbtn-brand-accent waves-attach waves-circle waves-light waves-effect" data-toggle="dropdown" aria-expanded="true"><span class="fbtn-text fbtn-text-left">Menu</span><span class="fbtn-ori icon">apps</span><span class="fbtn-sub icon">close</span></a>
			<div class="fbtn-dropup">
				<a class="fbtn fbtn-brand waves-attach waves-circle waves-light waves-effect" href="../list.html" target="_self"><span class="fbtn-text fbtn-text-left">题目列表</span><span class="icon">menu</span></a>
				<a class="fbtn fbtn-green waves-attach waves-circle waves-effect" href="../index.html" target="_self"><span class="fbtn-text fbtn-text-left">返回主页</span><span class="icon">home</span></a>
				<a class="fbtn waves-attach waves-circle waves-effect" href="http://www.lydsy.com/JudgeOnline/submitpage.php?id=4528" target="_blank"><span class="fbtn-text fbtn-text-left">提交代码</span><span class="icon">send</span></a>
				<a class="fbtn fbtn-orange waves-attach waves-circle waves-effect" href="http://www.lydsy.com/JudgeOnline/wttl/wttl.php?pid=4528" target="_blank"><span class="fbtn-text fbtn-text-left">试题讨论</span><span class="icon">chat</span></a>
				
			</div>
		</div>
	</div>

	<!-- js -->
	<script src="../js/jquery.min.js"></script>
	<script src="../js/base.min.js"></script>
	<script src="../js/project.min.js"></script>
</body>
</html>